package com.gemme.gemme.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gemme.gemme.R;
import com.gemme.gemme.wode.FaPiaoTaitouActivity;
import com.gemme.gemme.wode.ShopOrderInvoice;

import java.util.List;

public class FapiaoTaitouTypeDialog {
    BottomDialog dialog;
    private Activity mContext;
    private OnSelect onSelect;

    public FapiaoTaitouTypeDialog(Activity mContext){
        this.mContext = mContext;
    }

    public void showDialog(){
//new int[]{R.id.close}
        dialog = new BottomDialog(mContext, R.layout.fapiao_taitou_type_dialog,
                new int[]{R.id.close});


        dialog.show();
        initView();
        dialog.setOnBottomItemClickListener(new BottomDialog.OnBottomItemClickListener() {
            @Override
            public void onBottomItemClick(BottomDialog dialog, View view) {
                switch (view.getId()) {
                    case R.id.close:
                        dialog.dismiss();
                        break;

                }
            }
        });
    }
    TextView tv_add_new_taitou;
    LinearLayout ll_content;
    private void initView() {
        View view = dialog.getView();
        tv_add_new_taitou = view.findViewById(R.id.tv_add_new_taitou);

        ll_content = view.findViewById(R.id.ll_content);
        tv_add_new_taitou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mContext.startActivityForResult(new Intent(mContext, FaPiaoTaitouActivity.class),1);
            }
        });
    }


    public void setAllData(List<ShopOrderInvoice> list) {
        ll_content.removeAllViews();
        for (int i = 0; i < list.size(); i++) {
            addData(list.get(i));
        }
    }

    public void addData(ShopOrderInvoice shopOrderInvoice) {
        SIngleFapaiTaitouItemView itemView = new SIngleFapaiTaitouItemView(mContext);
        itemView.setData(shopOrderInvoice);
        ll_content.addView(itemView);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                if(onSelect != null){
                    onSelect.onSelect(itemView.getData());
                }
            }
        });
    }

    public void addonSelect(OnSelect onSelect){

        this.onSelect = onSelect;
    }



    public interface OnSelect{
        void onSelect(ShopOrderInvoice shopOrderInvoice);
    }
}
